import React from "react";
import { Navigate } from "react-router-dom";

// 定义 RouterAuth 的 Props 类型
interface RouterAuthProps {
  children: React.ReactNode;
}

export const RouterAuth: React.FC<RouterAuthProps> = ({ children }) => {
  const token = localStorage.getItem("token");

  if (token) {
    return <>{children}</>;
  } else {
    return <Navigate to="/login" replace />;
  }
};

export default RouterAuth;
